<?php
/**
* @package odal.core
* @author Volker Schubert <vs@brixlent.de>
* @since 1.1rc1
* @version $Id: node.php,v 1.3 2006/05/30 15:11:44 vschubert Exp $
*/
/**
* Abstract base class
* 
* Base class for nearly every class in odal.core.element and odal.core.meta
*
* @abstract
* @package odal.core
* @author Volker Schubert <vs@brixlent.de>
* @since 1.1rc1
* @version $Id: node.php,v 1.3 2006/05/30 15:11:44 vschubert Exp $
*/
class odal_Node extends cube_Object{
	var $m_id;
	var $m_name;
	var $m_modifyingDate;
	var $m_creatingDate;
	var $m_creater;
	var $m_modifier;
	var $m_state = 0;

	function delete(){
		$bRet = false;
		if ( $this->_pck_getState() != 1 ){
			$this->setState( 3 );
			$bRet = true;
		}//if
		//echo "(node->delete) this->_pck_getState():" . $this->_pck_getState() . "<br>";
		return $bRet;
	}//delete

	function toString(){
		print_r( $this );
	}//toString
	
	function update( $name ){
		$bRet = false;
		if ( ( $this->_pck_getState() == 0 ) || ( $this->_pck_getState() == 1 ) ){
			//echo "[node->update] this->getId(): " . $this->getId() . " - this->getName(): " . $this->getName() . "<br>";
			//echo "[node->update] this->_pck_getState(): *" . $this->_pck_getState(). "*<br>";
			$this->m_name = $name;
			$bRet = true;
		}//if
		$this->_pck_setStateAfterUpdate();
		//echo "[node->update] this->_pck_getState(): *" . $this->_pck_getState(). "*<br>";
		//echo "[node->update] bRet: *" . $bRet . "*<br>";
		return $bRet;
	}//update

	function _pck_setStateAfterUpdate(){
		if ( $this->_pck_getState() == 0 ){
			$this->setState( 2 );
		}//if
	}//_pck_setStateAfterUpdate
	
	function getId(){
		return $this->m_id;
	}//getId

	function getName(){
		return $this->m_name;
	}//getName

	function getModifyingDate()	{
		return $this->m_modifyingDate;
	}//getModifyingDate

	function getCreatingDate(){
		return $this->m_creatingDate;
	}//getCreatingDate

	function getCreater(){
		return $this->m_creater;
	}//getCreater

	function getModifier(){
		return $this->m_modifier;
	}//getModifier
	
	function _pck_getState(){
		return $this->m_state;
	}//_pck_getState

	function setId( $id ){
		$this->m_id = $id;
	}//setId

	function setState( $state ){
		$this->m_state = $state;
	}//setState

	function &getObjectFromCollectionById( $id, &$objColl, $debug = false ){
		$retobj = null;
		if ($debug){
//			echo "(node->getObjectFromCollectionById) $objColl:<br>";
//			print_r( $objColl );
//			echo "<br>";
		}//if
		if ( array_key_exists( $id, $objColl ) ){
			$retobj =& $objColl[$id];
		}//if
		return $retobj;
	}//&getObjectFromCollectionById

	function &getObjectFromCollectionByName( $name, &$objColl, $debug = false ){
		$retobj = null;
		foreach ( $objColl as $oSobj ){
			if (  $debug ){
				echo "(node->getObjectFromCollectionByName) class: " . get_class( $oSobj ) . "<br>";
				echo "(node->getObjectFromCollectionByName) name: " . $oSobj->getName() . "<br>";
			}//if
			if ( $oSobj->getName() == $name ){
				$retobj =& $objColl[$oSobj->getId()];
				break; 
			}//if  
		}//foreach
		return $retobj;
	}//&getObjectFromCollectionByName

}//odal_Node
?>